package com.azirkxs.clothes.cys.controller;

import com.azirkxs.clothes.common.vo.Result;
import com.azirkxs.clothes.cys.entity.ArmoireClothes;
import com.azirkxs.clothes.cys.service.IArmoireClothesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author azirkxs
 * @since 2023-04-09
 */
@RestController
@RequestMapping("/armoireClothes")
public class ArmoireClothesController {

    @Autowired
    IArmoireClothesService iArmoireClothesService;

    @GetMapping("/getClothesByArmoireId")
    public Result<Map<String,Object>> getUserInfo(@RequestParam("id") Integer armoire_id){
        //根据衣柜ID查询衣服
        Map<String,Object> data = iArmoireClothesService.getClothesByArmoireId(armoire_id);
        if(data!=null){
            return Result.success(data);
        }

        return Result.fail(20003,"获取信息失败");
    }

    //把衣服添加到衣柜
    @PostMapping("/addClothesToArmoire")
    public Result<Map<String,Object>> addClothesToArmoire(@RequestParam("clothesId") Integer clothes_id,
                                                          @RequestParam("armoireId") Integer armoire_id){
        ArmoireClothes armoireClothes = new ArmoireClothes();
        armoireClothes.setArmoireId(armoire_id);
        armoireClothes.setClothesId(clothes_id);
        iArmoireClothesService.save(armoireClothes);
        return Result.success("增加成功");
    }
}
